package com.three.menumanagement.controller;

import com.three.core.entity.Menu;
import com.three.core.vo.R;
import com.three.menumanagement.mapper.MenuMapper;
import com.three.menumanagement.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/menuManagement/menu")
public class MenuController {
    @Autowired
    private MenuService menuService;
    @Autowired
    private MenuMapper menuMapper;
    @PostMapping("/addMenu")
    public R addMenu(@RequestBody Menu menu){
        return menuService.addMenu(menu);
    }
    @DeleteMapping("/deleteMenu/{id}")
    public R deleteMenu(@PathVariable("id") Integer id){
        int i = menuMapper.deleteById(id);
        if (i>0){
            return new R<>(200,"删除成功",null);
        }else {
            return new R<>(400,"删除失败",null);
        }
    }
    @PutMapping("/updateMenu")
    public R updateMenu(@RequestBody Menu menu){
        return menuService.updateMenu(menu);
    }
}
